class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        if(s.length() == 0) return 0;
        int m = 0;
        int max = 1;
        int i, j;
        for(i = 1; i < s.length(); ++i) {
            for(j = m; j < i; ++j) {
                if(s[j] == s[i]) break;
            }
            if(j < i) {
                m = j + 1;
            } else {
                if(max < i - m + 1) max = i - m + 1;
            }
        }
        return max;
    }
};
